<template>
  <div style="margin-left: 50px; line-height: 28px;">
    <div style="margin-bottom: 20px;">快捷配置工具</div>
    <div class="kflexc">
      <div>
        <div style="margin-bottom: 20px;"><el-button round @click="tongbukai">快速同步</el-button></div>
        <div style="color: rgb(153, 153, 153);">将当前配置快速同步给已有其他产品</div>
      </div>
      <div style="margin-left: 60px;">
        <div style="margin-bottom: 20px;"><el-button round @click="yinyongkai">快速引用</el-button></div>
        <div style="color: rgb(153, 153, 153);">直接引用已有产品的设置</div>
      </div>
    </div>

    <el-dialog title="快速同步" :visible.sync="log" width="480px">
      <div class="kflexc">
        <div style="color: rgb(102, 102, 102);">快速同步</div>
        <div style="margin-left: 20px;">
          <el-select v-model="arr" filterable multiple placeholder="请选择产品:">
            <el-option v-for="item in prolists" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button round @click="log = false">取 消</el-button>
        <el-button type="danger" round @click="quedingtongbu">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog title="快速引用" :visible.sync="log2" width="480px">
      <div class="kflexc">
        <div style="color: rgb(102, 102, 102);">快速引用</div>
        <div style="margin-left: 20px;">
          <el-select v-model="yinyongid" filterable placeholder="请选择产品:">
            <el-option v-for="item in prolists" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button round @click="log2 = false">取 消</el-button>
        <el-button type="danger" round @click="quedingyinyong">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import axios from 'axios'
  export default {
    name: 'chanpindiqutongbu',
    props: ['warn_province','warn_city','warn_area_type','deliver_province'],
    data() {
      return {
        log:false,
        arr: [],
        prolists: [],
        all:{
          product_ids:"",
          warn_province:"",
          warn_city:"",
          warn_area_type:"",
          deliver_province:""
        },

        log2:false,
        yinyongall:{},
        yinyongid:""
      }
    },
    created() {
      this.getpros()
    },

    methods: {
      yinyongkai:function(){
        this.yinyongid = ""
        this.yinyongall = ""
        this.log2 = true
      },
      quedingyinyong:function(){
        axios.get('/api/plan-market/product/area/quick/quote?product_id='+this.yinyongid)
          .then(response => {
            if (response.data.msg.code == 0) {
              this.$emit('yinyongall',response.data.data)
              this.log2 = false
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },
      tongbukai:function(){
        this.$emit('shuaxin')
      },
      quedingtongbu:function(){
        if(this.arr == ""){
          this.$message.error('请选择要同步的产品');
          return false
        }
        this.all = {
          product_ids:this.arr.toString(),
          warn_province:this.warn_province,
          warn_city:this.warn_city,
          warn_area_type:this.warn_area_type,
          deliver_province:this.deliver_province
        }
        this.$confirm('确定要同步吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          axios.post('/api/plan-market/product/area/quick/sync',this.all)
            .then(response => {
              if (response.data.msg.code == 0) {
                this.$message.success('操作成功');
                this.log = false
              } else {
                this.$message.error(response.data.msg.info);
              }
            })
        })

      },
      //获取全部基础产品
      getpros: function() {
        axios.get('/api/gth/products/list?page_size=2000')
          .then(response => {
            if (response.data.msg.code == 0) {
              this.prolists = response.data.data.data
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },
    },

  }
</script>
